var processSuccessDeleteElementResponse = function(treePanelObj, node, response, opts) {
	treePanelObj.el.unmask();
	
	var responseJson = Ext.util.JSON.decode(response.responseText);

	if (responseJson.success === "true") {
		node.remove();
		CSViewerApp.EventManager.fireEvent('delete', node);
	} else {
		Ext.Msg.alert('ERROR', 'An error occured during object deletion on the server.\n' + (responseJson.errorMessage ? responseJson.errorMessage : ''));
	}
}

var processFailureDeleteElementResponse = function(treePanelObj, node, response, opts) {
	treePanelObj.el.unmask();
	
	Ext.Msg.alert('ERROR', 'Unknown error occured.');
}

var onConfirmDelete = function(btn, treePanelObj) {
	if (btn == 'yes') {		
		treePanelObj.el.mask('Deleting...', 'x-mask-loading');
		
		var selNode = treePanelObj.getSelectionModel().getSelectedNode();
		
		Ext.Ajax.request({
			url    : 'dispatcher/deleteElement',
			
			params : {
				node: selNode.id
			},
						
			success: function(response, opts) {
				processSuccessDeleteElementResponse(treePanelObj, selNode, response, opts);
			},
			
			failure: function(response, opts) {
				processFailureDeleteElementResponse(treePanelObj, selNode, response, opts);
			}
		});
	}
}